<template>
  <div class="div_box">
    <h1>登录页面</h1>
    <el-form
      :model="ruleForm"
      status-icon
      label-width="100px"
      class="demo-ruleForm"
      id="from"
    >
      <el-form-item label="账号" prop="pass">
        <el-input type="text" v-model="ruleForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="ruleForm.password" type="password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="login" id="buttom" type="success">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {LOGIN} from '../request/http'
export default {
  data() {
    return {
      ruleForm: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    async login() {
      if (this.ruleForm.username == "" && this.ruleForm.password == "") {
       this.$message({
          message: '不能为空',
          type: 'warning'
        })
        return false;
      } else {
        const {data:res} =await LOGIN (`user/login.do`,this.ruleForm);
        localStorage.setItem('token',res.data.status) //本地存储
        console.log(res)
        this.$message({
          message: '登录成功',
          type: 'success'
        })
        this.$router.push({path:'/home'})
      }
    },
  },
};
</script>

<style lang="scss">
  .div_box{
    width: 400px;
    margin: 100px auto;
    border: 1px solid rgb(233, 11, 85);
    border-radius:20px;
  }
  #from{
    text-align: center;
    margin-right:100px;
    margin-top:20px;
  }
  h1{
    width: 100%;
    height: 50px;
    border-bottom:1px solid gainsboro;
    text-align: center;
  }
  #buttom{
    width: 100%;
    text-align: center;
  }
</style>